package com.neusoft.nepg.gridders.controller;

import com.neusoft.nepg.gridders.entity.Feedback;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.VBox;

import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

import static com.neusoft.nepg.gridders.utils.FileUtils.ListReader;

public class FeedbackListViewController implements Initializable {

    @FXML
    private VBox vBox;

    public void initialize(URL url, ResourceBundle rb) {
        List<Feedback> feedbackList = ListReader("feedback.txt");
        for(Feedback feedback : feedbackList) {
            try {
                //get the target format
                FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("../view/CardView.fxml"));
                AnchorPane cardView = fxmlLoader.load();
                //set the data to the card view
                CardViewController cardViewController = fxmlLoader.getController();
                cardViewController.setData(feedback);
                //add the card view to the vBox
                vBox.getChildren().add(cardView);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }

}
